package com.bawei.doctor.controller;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bawei.doctor.config.OSSFileUtil;
import com.bawei.doctor.vo.DoctorVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.bawei.doctor.entity.HospitalDoctorEntity;
import com.bawei.doctor.service.HospitalDoctorService;
import com.bawei.common.utils.PageUtils;
import com.bawei.common.utils.R;
import org.springframework.web.multipart.MultipartFile;


/**
 * 医生表
 *
 * @author wtj
 * @email 1756179378@qq.com
 * @date 2021-12-09 16:49:01
 */
@RestController
@RequestMapping("doctor/hospitaldoctor")
public class HospitalDoctorController {
    @Autowired
    private HospitalDoctorService hospitalDoctorService;

    //审核后修改医师状态
    @GetMapping("/updateStatus/{doctorId}/{status}")
    public String updateStatus(@PathVariable("doctorId") Integer doctorId,@PathVariable("status") Integer status){

        return hospitalDoctorService.updateStatus(doctorId,status);
    }

    //远程查询医师
    @GetMapping("/listDoctors")
    public List<HospitalDoctorEntity> listDoctors(){
        return hospitalDoctorService.list();
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = hospitalDoctorService.queryPage(params);

        return R.ok().put("page", page);
    }


//    /**
//     * 医院统计信息列表
//     */
//    @GetMapping("/doctorList")
//    public R doctorList(@RequestParam Map<String, Object> params){
//        PageUtils doctorList = hospitalDoctorService.doctorList(params);
//        return R.ok().put("page", doctorList);
//    }

    /**
     * 查询所有医院的统计信息
     */
    @GetMapping("/enterHospital")
    public R enterHospital(@RequestParam(value = "typeName",defaultValue = "") String typeName,
                           @RequestParam(value = "parentId",defaultValue = "") int parentId,
                           @RequestParam(value = "page",defaultValue = "1") int page,
                           @RequestParam(value = "size",defaultValue = "2") int size
                           ){
        PageUtils enterHospital = hospitalDoctorService.enterHospital(typeName,parentId,page,size);
        return R.ok().put("page", enterHospital);
    }

    // 添加医生查询三级分类
    @GetMapping("/selecthospital")
    public R selecthospital(
                           @RequestParam(value = "parentId",defaultValue = "") int parentId
    ){
       List<DoctorVo>  enterHospital= hospitalDoctorService.selecthospital(parentId);
        return R.ok().put("page", enterHospital);
    }

    @PostMapping("/tu")
    public String tu(MultipartFile file) throws IOException {
        String s = OSSFileUtil.uploadFile(file);
        return s;
    }
    /**
     * 查询该医院下的科室统计信息
     */
    @GetMapping("/administrative")  //科室
    public R administrativeList(@RequestParam(value = "typeName",defaultValue = "") String typeName,
                           @RequestParam(value = "parentId",defaultValue = "") int parentId,
                           @RequestParam(value = "page",defaultValue = "1") int page,
                           @RequestParam(value = "size",defaultValue = "2") int size
    ){
        PageUtils enterHospital = hospitalDoctorService.administrative(typeName,parentId,page,size);
        return R.ok().put("page", enterHospital);
    }

    /**
     * 该科室下的医生等级信息
     */
    @GetMapping("/doctorlevel")  //科室
    public R doctorlevel(@RequestParam(value = "typeName",defaultValue = "") String typeName,
                                @RequestParam(value = "parentId",defaultValue = "") int parentId,
                                @RequestParam(value = "page",defaultValue = "1") int page,
                                @RequestParam(value = "size",defaultValue = "2") int size
    ){
        PageUtils enterHospital = hospitalDoctorService.doctorlevel(typeName,parentId,page,size);
        return R.ok().put("page", enterHospital);
    }


    /**
     *  查询该等级下的医生统计信息
     */
    @GetMapping("/administrativeList")
    public R administrativeList(@RequestParam Map<String, Object> params){

        PageUtils administrativeList=hospitalDoctorService.administrativeList(params);

        return R.ok().put("administrativeList",administrativeList);
    }


    /**
     * 添加医生
     */
    @PostMapping("adddoctor")
    public R adddoctor(){

        return R.ok();
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{doctorId}")
    public R info(@PathVariable("doctorId") Integer doctorId){
		HospitalDoctorEntity hospitalDoctor = hospitalDoctorService.getById(doctorId);

        return R.ok().put("hospitalDoctor", hospitalDoctor);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody HospitalDoctorEntity hospitalDoctor){
		hospitalDoctorService.save(hospitalDoctor);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody HospitalDoctorEntity hospitalDoctor){
		hospitalDoctorService.updateById(hospitalDoctor);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] doctorIds){
		hospitalDoctorService.removeByIds(Arrays.asList(doctorIds));

        return R.ok();
    }

}
